<ol class="breadcrumb" >
    <li> <i class="fa fa-anchor"></i>
        &nbsp;权限管理
    </li>
    <li>角色列表</li>
</ol>

<div class="col-xs-12 info-center">
    <div class="bs-callout bs-callout-warning">
        <h4>
            系统使用单位: <strong>{:C('COLLEGE_NAME')}</strong>
        </h4>
        <if condition="$administrator eq 1">
        <form id="add_node"  action="__URL__/node" method="post">
                <div class="col-xs-4">
                    <div class="input-group">
                        <span class="input-group-addon">名称</span>
                        <input type="text" id="title" name="title" class="form-control" placeholder="名称">
                    </div>
                </div>
                <div class="clearfix" style="margin:5px;"></div>

                <div class="col-xs-4">
                    <div class="input-group">
                        <span class="input-group-addon">级别</span>
                        <select name="level" class="form-control required">
                            <option value="Action">Action</option>
                            <option value="Controller">Controller</option>
                        </select>
                    </div>
                </div>
                <div class="clearfix" style="margin:5px;"></div>
                
                <div class="col-xs-4">
                    <div class="input-group">
                        <span class="input-group-addon">Controller</span>
                        <input type="text" id="Controller" name="Controller" class="form-control" placeholder="Controller">
                    </div>
                </div>
                <div class="clearfix" style="margin:5px;"></div>

                <div class="col-xs-4">
                    <div class="input-group">
                        <span class="input-group-addon">Action</span>
                        <input type="text" id="Action" name="Action" class="form-control" placeholder="Action">
                    </div>
                </div>
                <div class="clearfix" style="margin:5px;"></div>

                <div class="col-xs-4">
                    <button class="btn btn-warning" type="submit"><i class="fa fa-plus"></i>&nbsp;添加权限节点</button>
                </div>
            </form>
        </if>
            <div class="clearfix"></div>
            <p>系统各模块权限列表如下,请准确选择角色权限</p>
    </div>
</div>

<div class="col-xs-12 info-center">
    <div class="panel panel-mcit">

        <div class="panel-heading"> <i class="fa fa-list"></i>
            &nbsp;&nbsp;{$roleInfo.name}&nbsp;权限列表
        </div>

        <div class="panel-body">
        <div class="panel-group" id="accordion">

        <volist name="nodeTree" id="vo">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#{$vo.name}" class="collapsed btn-block">{$vo.title}</a>
                    </h4>
                </div>
                <div id="{$vo.name}" <if condition="$i eq 1">
                    class="panel-collapse collapse in" style="height: auto;"
                    <else/>
                    class="panel-collapse collapse" style="height: 0;"
                </if>
                >
                <div class="panel-body">
                    <volist name="vo.detail" id="vovo">
                        <div class="col-xs-4">
                            <if condition="$vovo.checked eq 1">
                                <a class="bg-info btn-block" href="#404" data-code="{$vovo.code}" data-title="{$vovo.title}">
                                    <span>{$vovo.title}</span>
                                    <span class="pull-right" style="font-size:16px;padding-top:4px">
                                        <i class="fa fa-check-square-o"></i>
                                    </span>
                                </a>
                                <else/>
                                <a class="bg-danger btn-block" href="#404" data-code="{$vovo.code}" data-title="{$vovo.title}">
                                    <span>{$vovo.title}</span>
                                    <span class="pull-right" style="font-size:16px;padding-top:4px">
                                        <i class="fa fa-warning"></i>
                                    </span>
                                </a>
                            </if>
                        </div>
                    </volist>
                </div>
                </div>
            </div>
        </volist>
        <form id="set_access" class="add_form" action="__URL__/setAccess" method="post">
            <input type="hidden" name="authcode" id="authcode" value="{$roleInfo.authcode}">
            <input type="hidden" name="authstr" id="authstr" value="{$roleInfo.authstr}">
            <input type="hidden" name="role" value="{$roleInfo.id}">
            <div class="clearfix"></div>
            <div class="col-xs-4 search-col">
                <button class="btn btn-warning" type="submit"> <i class="fa fa-plus"></i>
                    &nbsp;确认保存
                </button>
            </div>
            <div class="clearfix"></div>
        </form>
    </div>
</div>
</div>
</div>


<script type="text/javascript">
    function setFormData(){
        var authcode   = '';
        var authstr = '';
        $(".bg-info").each(function (i, item){
            authcode += authcode  =='' ? $(item).attr('data-code')  : ','+$(item).attr('data-code');
            authstr  += authstr   =='' ? $(item).attr('data-title') : ','+$(item).attr('data-title');
        }); 
        $("#authcode").val(authcode);
        $("#authstr").val(authstr);
    }
    $(".info-center").on("click",'.bg-info',function(){
        $(this).removeClass('bg-info').addClass('bg-danger').find('i').removeClass('fa-check-square-o').addClass('fa-warning');
        setFormData();
    });

    $(".info-center").on("click",'.bg-danger',function(){
        $(this).removeClass('bg-danger').addClass('bg-info').find('i').removeClass('fa-warning').addClass('fa-check-square-o');
        setFormData();
    });

    $("#set_access").ajaxForm({
        dataType:'json',
        clearForm:false,
        // beforeSubmit:function(){
        //     return true;
        // },
        success:function(data){
            if(data.state==100){
                alertify.success(data.msg);
                location.href = data.url;
            }else{
                alertify.error(data.msg);
            }
        }
    });

    $("#add_node").ajaxForm({
        dataType:'json',
        clearForm:false,
        beforeSubmit:function(){
            if($("#Controller").val()==''){
                alertify.error("请填写Controller");
                return false;
            }
            if($("#title").val()==''){
                alertify.error("请填写title");
                return false;
            }
            return true
        },
        success:function(data){
            if(data.state==100){
                alertify.success(data.msg);
                location.reload(true);
            }else{
                alertify.error(data.msg);
            }
        }
    }); 
</script>